﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;

namespace BabyLearnEnglish_srcum_demo
{
    public partial class Form1 : Form
    {
        public static int level = 0;
        public static string uername = "unname";
        public static int score = 0;
        //public static int currentQ = 0;
        public static List<Question> listCurQ = new List<Question>();
        public static List<Question> listQ = new List<Question>();
        public static int[] arrOld = new int[100];

        public static bool isFinished = false;
        public static String Lang = "Vi";

        public Form1()
        {
            InitializeComponent();
        }

        private void btnChoi_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < (level + 1) * 2; i++)
            {
                Random random = new Random();
                int randomNumber = random.Next(0, listQ.Count);
                int pos = Array.IndexOf(arrOld, randomNumber);
                if (pos == -1)
                {
                    listCurQ.Add(listQ[randomNumber]);
                    arrOld[i] = randomNumber;
                }
                else
                    i--;
            }
            this.Hide();
            frmChoi frm = new frmChoi();
            frm.ShowDialog();
            this.Show();
            if (isFinished)
            {
                this.Hide();
                frmXemDiem frm1 = new frmXemDiem();
                frm1.ShowDialog();
                this.Show();
            }

            level = 0;
            uername = "unname";
            score = 0;

            listCurQ = new List<Question>();
            arrOld = new int[100];
            isFinished = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // music
            //--------------------------------------------------
            SoundPlayer soud = new SoundPlayer("../../data/audio/audio1.wav");
            soud.PlayLooping();
            //soud.Play();
            //---------------------------
            level = 0;
            uername = "unname";
            score = 0;

            listCurQ = new List<Question>();
            listQ = new List<Question>();
            arrOld = new int[100];
            Form1.listQ = new Question().getList();
            isFinished = false;
            setUI();
        }

        private void btnChonCapDo_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmChonCapDo frm = new frmChonCapDo();
            frm.ShowDialog();
            this.Show();
        }

        private void bntBangXepHang_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmXemDiem frm = new frmXemDiem();
            frm.ShowDialog();
            this.Show();
        }

        private void btnTroGiup_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmHuongDan frm = new frmHuongDan();
            frm.ShowDialog();
            this.Show();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void rdVi_CheckedChanged(object sender, EventArgs e)
        {
            Lang = "Vi";
            setUI();
        }

        private void rdEn_CheckedChanged(object sender, EventArgs e)
        {
            Lang = "En";
            setUI();
        }

        public void setUI()
        {
            if (Lang == "Vi")
            {
                this.Text = "Cửa sổ chính";
                label1.Text = "Học tiếng anh";
                btnChoi.Text = "Bắt đầu";
                btnChonCapDo.Text = "Chọn cấp độ";
                btnTroGiup.Text = "Cách chơi";
                btnBangXepHang.Text = "Bảng xếp hạng";
                btnThoat.Text = "Thoát";
            }
            else
            {
                this.Text = "Main menu window";
                label1.Text = "Learn English";
                btnChoi.Text = "Start";
                btnChonCapDo.Text = "Levels";
                btnTroGiup.Text = "How to play";
                btnBangXepHang.Text = "High Scores";
                btnThoat.Text = "Quit";
            }
        }
    }
}
